using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Text;

namespace SqlToolkit.Oracle.Schema
{
    public class SqlDbTableFieldConstraint : SqlBase
    {
        internal SqlDbTableFieldConstraint() { }
        internal SqlDbTableFieldConstraint(OracleDB conn) { _conn = conn; }

        #region CONSTRAINT_NAME
        protected string constraint_name = string.Empty;
        public string ConstraintName
        {
            get { return constraint_name; }
            //set{if(value != constraint_name) constraint_name = value;}
        }
        #endregion
        #region TABLE_NAME
        protected string table_name = string.Empty;
        public string TableName
        {
            get { return table_name; }
            //set{if(value != table_name) table_name = value;}
        }
        #endregion
        #region COLUMN_NAME
        protected string column_name = string.Empty;
        public string ColumnName
        {
            get { return column_name; }
            //set{if(value != column_name) column_name = value;}
        }
        #endregion
        #region POSITION
        protected int pos = int.MinValue;
        public int Position
        {
            get { return pos; }
            //set{if(value != pos) pos = value;}
        }
        #endregion

        internal static SqlDbTableFieldConstraint Build(OracleDB conn, System.Data.IDataReader r)
        {
            SqlDbTableFieldConstraint ret = new SqlDbTableFieldConstraint(conn);

            ret.constraint_name = (r.IsDBNull(0)) ? string.Empty : r.GetString(0);
            ret.table_name = (r.IsDBNull(1)) ? string.Empty : r.GetString(1);
            ret.column_name = (r.IsDBNull(2)) ? string.Empty : r.GetString(2);
            ret.pos = (r.IsDBNull(3)) ? 0 : r.GetInt32(3);

            return ret;
        }

        internal static SqlDbTableFieldConstraintCollection BuildCollection(OracleDB conn, System.Data.IDataReader r)
        {
            SqlDbTableFieldConstraintCollection ret = new SqlDbTableFieldConstraintCollection();

            while(r.Read())
                ret.Add(SqlDbTableFieldConstraint.Build(conn, r));

            return ret;
        }
    }
}
